<?php
namespace app\user\controller;
use think\Db;
use think\Session;

Class Password extends Common{
    protected $token = '_IdoNotKnowWhatTheKeyIs__LetMeGo';

    public function index(){

        return $this->fetch();
    }

    public function edit(){
        $token = $this->token;
        $params = $this->params;
        if($params['old_password']==$params['new_password']){
            return_msg(0,'新旧密码一致！');
        }
        $params['id'] = $this->admin['id'];
        $params['old_password'] = md5(md5($token . $params['old_password'] . $token));
        $is_exist = obj_decode($this->read($params['id'],['admin_password'=>$params['old_password']]));
        if($is_exist['code']){
            $params['admin_password'] =  md5(md5($token . $params['new_password'] . $token));
            $res = obj_decode( $this->update($params) );
            if($res['code']){
                Session::delete('admin');

                return_msg(1,'更新成功!',[],'/admin/member/login');
            }
        }
        else{
            return_msg(0,'旧密码错误或请求失败！',[]);
        }
    }

}